package com.hyt.it.ogt.kq.common.bm.utils;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.core.util.FastJsonUtil;

import cn.hutool.core.util.ArrayUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @program: it-ogt-bm
 * @description: 用于处理feign远程调用的工具类
 * @author: Yang HuanKun
 * @create: 2022-02-25 16:54
 **/
@Slf4j
public class RemoteUtil {

    private final static Integer[] ALL_RESPONSE_SUCCESS_CODE = {200, 20000, 12001, 13001, 14001, 15001, 16001, 17001, 18001, 19001, 30000, 40001};

    /**
     * 远程接口响应错误码
     *
     * @param apiResponse
     * @return
     */
    public static boolean isFail(ApiResponse<?> apiResponse) {
        if (log.isDebugEnabled()) {
            log.debug("# remote response data：{}", FastJsonUtil.getBeanToJson(apiResponse));
        }
        Integer code = apiResponse.getCode();
        return !ArrayUtil.contains(ALL_RESPONSE_SUCCESS_CODE, code);
    }
    
    /**
     * 远程接口响应成功码
     *
     * @param apiResponse
     * @return
     */
    public static boolean isSuccess(ApiResponse<?> apiResponse) {
        if (log.isDebugEnabled()) {
            log.debug("# remote response data：{}", FastJsonUtil.getBeanToJson(apiResponse));
        }
        Integer code = apiResponse.getCode();
        return ArrayUtil.contains(ALL_RESPONSE_SUCCESS_CODE, code);
    }
}
